package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.SetmealDetailsDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.SetmealDetails;
import com.itheima.service.SetmealDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 套餐详情服务
 */
@Service(interfaceClass = SetmealDetailsService.class)
@Transactional
public class SetmealDetailsImpl implements SetmealDetailsService {
    //注入DAO对象
    @Autowired
    private SetmealDetailsDao setmealDetailsDao;
    public void add(SetmealDetails setmealDetails) {
        setmealDetailsDao.add(setmealDetails);
    }

    //套餐预约信息分页查询
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        Integer pageSize = queryPageBean.getPageSize();
        String queryString = queryPageBean.getQueryString();//查询条件
        //完成分页查询，基于mybatis框架提供的分页助手插件完成
        PageHelper.startPage(currentPage,pageSize);

        Page<SetmealDetails> page = setmealDetailsDao.selectByCondition(queryString);
        long total = page.getTotal();
        List<SetmealDetails> rows = page.getResult();
        return new PageResult(total,rows);
    }

    //根据ID删除预约信息
    public void deleteById(Integer id) {
        setmealDetailsDao.deleteById(id);
    }
    //修改套餐预约详情
    public void edit(SetmealDetails setmealDetails) {
        setmealDetailsDao.edit(setmealDetails);
    }
    //通过ID查询一条套餐的详细信息
    @Override
    public SetmealDetails findById(Integer id) {
        return setmealDetailsDao.findById(id);
    }
    //查询所有的套餐详情
    @Override
    public List<SetmealDetails> findAll() {
        return setmealDetailsDao.findAll();
    }

    @Override
    public void updateOrderStatus(SetmealDetails setmealDetails) {
        setmealDetailsDao.updateOrderStatus(setmealDetails);
    }


}
